import java.sql.*;

public class JdbcMySQLTest {
    static public void main(String [] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");

        String url = "jdbc:mysql://localhost:3306/company?characterEncoding=utf8&useSSL=true";

        Connection conn = DriverManager.getConnection(url, "root", "123123");

        Statement st = conn.createStatement();

        // ResultSet rs = st.executeQuery("select * from stu");
        ResultSet rs = st.executeQuery("desc emp");

        rs.last();
        int row = rs.getRow();
        int col = rs.getMetaData().getColumnCount();
        System.out.printf("row = %d, col = %d\n", row, col);
        rs.absolute(0);
        int i = 0;

        while (rs.next()) {
            for (i = 1; i <= col; ++i) {
                System.out.printf("%8s | ", rs.getString(i));
            }
            System.out.println();
            // System.out.printf("id = %d, name = %s\n", rs.getInt(1), rs.getString(2));
            // System.out.printf("%s ROW = %d\n", rs.getString("Null"), rs.getRow());
        }

        System.out.printf("row = %d\n", rs.getRow());
        System.out.println("==============================");
        rs.absolute(0);

        while (rs.next()) {
            // System.out.printf("id = %d, name = %s\n", rs.getInt(1), rs.getString(2));
            System.out.printf("%s\n", rs.getString("Null"));
        }

        // st.executeUpdate("insert into stu(`name`) values(\"张三\")");

        st.close();
        conn.close();
    }
}
